package com.yqg.education.service.impl;

import com.yqg.education.entity.LivePlayback;
import com.yqg.education.mapper.LivePlaybackMapper;
import com.yqg.education.service.ILivePlaybackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yqg.education.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * LivePlaybackServiceImpl 服务实现类
 *
 * @author zxf
 * @since 2025-07-11
 */
@Service
public class LivePlaybackServiceImpl extends ServiceImpl<LivePlaybackMapper, LivePlayback> implements ILivePlaybackService {
    @Resource
    private LivePlaybackMapper livePlaybackMapper;

    @Resource
    private IUserService userService;

    @Override
    public Map<String, Object> stuFindPage(Long pageNum, Long pageSize, Long courseId, Long teachId, Long stuId) {
        pageNum = pageNum * pageSize - pageSize;
        List<Long> courseIds = new ArrayList<>();
        // 课程Id为空，表示查找所有
        if (courseId == null) {
            courseIds = userService.getCourseIdByUserId(stuId.intValue());
        }

        List<LivePlayback> livePlaybackList = livePlaybackMapper.stuFindPage(pageNum, pageSize, courseIds, courseId, teachId);
        Long count = livePlaybackMapper.stuFindCount(courseIds, courseId, teachId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("records", livePlaybackList);
        map.put("total", count);
        return map;
    }

    @Override
    public Map<String, Object> findPage(Long pageNum, Long pageSize, Long courseId, Long teachId) {
        pageNum = pageNum * pageSize - pageSize;
        List<LivePlayback> livePlaybackList = livePlaybackMapper.findPage(pageNum, pageSize, courseId, teachId);
        Long count = livePlaybackMapper.findCount(courseId, teachId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("records", livePlaybackList);
        map.put("total", count);
        return map;
    }
}
